package com.example.springtaskschedule.controller;

import com.example.springtaskschedule.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * MyController
 *
 * @author zhouxianfeng
 * @date 2021-4-25
 */
@RestController
@RequestMapping("/my")
@Slf4j
public class MyController {

    @Autowired
    private TestService testService;


    @GetMapping("/test")
    public void test() throws Exception {
        testService.testAsync();
    }

    @GetMapping("/test1")
    public String test1() throws Exception {

        return testService.test().get();
    }

    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Autowired
    @Qualifier("test1TaskExecutor")
    ThreadPoolTaskExecutor test1TaskExecutor;

    @GetMapping("/close/{id}")
    public void test1(@PathVariable String id) throws Exception {
        log.info("开始关闭线程");
        test1TaskExecutor.shutdown();
    }


}
